package com.yvon.maple.service.auth.authentication.granter;

import com.yvon.boot.jwt.model.AuthInfo;
import com.yvon.boot.jwt.utils.TokenUtil;
import com.yvon.boot.redis.service.RedisService;
import com.yvon.maple.service.auth.param.LoginParam;
import com.yvon.maple.service.auth.service.SecurityUserService;
import com.yvon.maple.service.auth.valicode.validate.code.processor.CodeValidator;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.stereotype.Component;

/**
 * 账号密码登录获取token
 *
 * @author : Yvon
 * @since : 2021-08-25
 */
@Component(PasswordTokenGranter.GRANT_TYPE)
public class PasswordTokenGranter extends AbstractTokenGranter implements TokenGranter {

    public static final String GRANT_TYPE = "password";

    public PasswordTokenGranter(TokenUtil tokenUtil, AuthenticationManager authenticationManager, SecurityUserService securityUserService, CodeValidator codeValidator, RedisService redisService) {
        super(tokenUtil, authenticationManager, securityUserService, codeValidator, redisService);
    }

    @Override
    public AuthInfo grant(LoginParam tokenParameter) {
        validateCode(tokenParameter);
        return login(tokenParameter);
    }
}
